
function trim(val)
 { 
	return val.replace(/(\s*$)/g, "");  
}

function setProvince()
{
	Ts_areaInfo.getAreaClassByUpId('000000000000000',function(data){
		DWRUtil.removeAllOptions('province');
		DWRUtil.addOptions('province',{'':'请选择'});
		DWRUtil.addOptions('province',data);
	})
}
function setCitys(prov)
{
   var provence=prov;
	 Ts_areaInfo.getAreaClassByUpId(provence,function(data){
		DWRUtil.removeAllOptions('eparchy_code');
		DWRUtil.addOptions('eparchy_code',{'':'请选择'});
		DWRUtil.addOptions('eparchy_code',data);
		DWRUtil.removeAllOptions('city_code');
		DWRUtil.addOptions('city_code',{'':'请选择'});
	});
}

function setAreas(city_id){
	Ts_areaInfo.getAreaClassByUpId(city_id,function(data){
	 	DWRUtil.removeAllOptions('city_code');
     	DWRUtil.addOptions('city_code',{'':'请选择'});
	 	DWRUtil.addOptions('city_code',data);
	});
}




function subForm(flag){
		if(flag=='add'){
			if(trim(document.getElementById('user_name').value)==""){
			alert('请输入登陆账号！');
			document.getElementById('user_name').focus();
			return false;
			}
			if(trim(document.getElementById('passwd').value)==""){
					alert('请输入密码！');
					document.getElementById('passwd').focus();
					return false;
			}
			//document.getElementById('real_name').value = document.getElementById('user_name').value;
			//document.getElementById('cust_name').value = document.getElementById('user_name').value;
		}else{
			if(trim(document.getElementById('cust_name').value)==""){
				alert('请输入会员姓名！');
				document.getElementById('cust_name').focus();
				return false;
			}
		} 
		
		if(trim(document.getElementById('nike_name').value)==""	){
				alert('请输入真实姓名！');
				document.getElementById('nike_name').focus();
				return false;
			}
		
		if(document.getElementById('user_class').value==""){
				alert('请选择会员级别！');
				document.getElementById('user_class').focus();
				return false;
			}		
		document.getElementById('cust_class').value = document.getElementById('user_class').value;	
		
		
		var cust_start_date=document.getElementById('cust_start_date').value ;
		if( document.getElementById("cust_start_date").value==""){
	 		alert('请填写服务开始时间！');
			document.getElementById('cust_start_date').focus();
			return false;
	 	}
		var cust_end_date=document.getElementById('cust_end_date').value ;
		if( document.getElementById("cust_end_date").value==""){
	 		alert('请填写服务结束时间！');
			document.getElementById('cust_end_date').focus();
			return false;
	 	}
		
		  var cellphone = document.addForm.cellphone.value;
	   var myreg1=/^[1][\d]{10}$/;
	 	if(cellphone!=""&&!myreg1.test(cellphone)){
		   alert("请输入有效的手机号码！");
		   document.getElementById("cellphone").focus();
		   return false;
		}
		
		  //把传真号码和区号拼接在一起
	   var group_contact_phone = document.addForm.phone.value;
	  var myreg2 =/^((0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;
	  if(group_contact_phone!=""&&!myreg2.test(group_contact_phone)){
		   alert("请输入有效的固定电话号码！如0551-5310137");
		   document.getElementById("phone").focus();
		   return false;
		}

	  var email = document.addForm.email.value;
	  var fax = document.addForm.fax.value;
	  var msn = document.addForm.msn.value;
	  var post_code = document.addForm.post_code.value;
	  var chemEmails=/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
	
		if (email!=""&&!chemEmails.test(email)){
			alert("Email的格式不正确");
			document.getElementById("email").focus();
			return false;
	  }	
	  
	  if(fax!=""&&!myreg2.test(fax)){
		alert("传真格式不正确！");
		document.getElementById("fax").focus();
		return false;
	  }

	  if (msn!=""&&!chemEmails.test(msn)){
			alert("msn的格式不正确");
			document.getElementById("msn").focus();
			return false;
	  }
	  
	  if(post_code!=""&&post_code.length!=6){
			alert("邮政编码格式不正确");
			document.getElementById("post_code").focus();
			return false;
	  }
	  
	 var start_attr=""; 
  if(document.getElementById("province").value!="")
  {
      start_attr = document.getElementById("province").value+"|"; 
  }

  if(document.getElementById("eparchy_code").value!="")
  {
      start_attr += document.getElementById("eparchy_code").value+"|"; 
  }

  if(document.getElementById("city_code").value!="")
  {
      start_attr += document.getElementById("city_code").value+"|"; 
  }
  
  if(start_attr!=""){
 	 document.getElementById("area_attr").value = start_attr;
 	}
 	if( document.getElementById("area_attr").value==""){
 		alert('请选择所在地区！');
		document.getElementById('province').focus();
		return false;
 	}
 	
 	
	document.addForm.submit();
}

function checkname(){
	var user_name = document.getElementById('user_name').value;
	
		var bool = true;
	jQuery.ajax({
		type: "POST",
		url: "/templets/html/jsp/checkUserName.jsp",
		data:"user_name=" + user_name,
		success: function(data){
			 if(data!=null && trim(data)!=""){
				if( data == 1 ){
					alert('该登陆账号已存在！');
					document.getElementById('user_name').value = '';
					document.getElementById('user_name').focus();
					bool = false;
				}
			 }
		}
	});
	return bool;
}



  
function isNum(){
	
			if(isNaN(document.getElementById('phone').value)){

				alert('内容必须是数字！');

				document.getElementById('phone').value="";
				document.getElementById('phone').focus();
				return false;

			}
			if(isNaN(document.getElementById('inter_num').value)){

				alert('内容必须是数字！');

				document.getElementById('inter_num').value="";
				document.getElementById('inter_num').focus();
				return false;

			}
				if(isNaN(document.getElementById('cellphone').value)){

				alert('内容必须是数字！');

				document.getElementById('cellphone').value="";
				document.getElementById('cellphone').focus();
				return false;

			}
				if(isNaN(document.getElementById('fax').value)){

				alert('内容必须是数字！');

				document.getElementById('fax').value="";
				document.getElementById('fax').focus();
				return false;

			}
				if(isNaN(document.getElementById('qq').value)){

				alert('内容必须是数字！');

				document.getElementById('qq').value="";
				document.getElementById('qq').focus();
				return false;

			}
				if(isNaN(document.getElementById('post_code').value)){

				alert('邮编必须是数字！');

				document.getElementById('post_code').value="";
				document.getElementById('post_code').focus();
				return false;

			}
	
	}

function ChangeOrg(){
	document.getElementById("org1").style.display = "none";
	document.getElementById("org2").style.display = "inline";
	document.getElementById("org_id").value = "";
}


	function searchForm(){
	 document.indexForm.submit();
	}
 function oper(val)
 {
    var size = document.getElementById('listsize').value;
		var all_news_id='';
		for(var i=0;i<size;i++){
			if(document.getElementById('checkone'+i).checked){
				all_news_id += document.getElementById('checkone'+i).value+'|';
			}
		}
		 document.getElementById('user_id').value = all_news_id;
		
		if(all_news_id==''){
			alert('请至少选择一条!');
			return false;
		}else{
   
    if(val=='0'){
    		  	document.indexForm.action='/doTradeReg.do';  //正常
    		  	document.getElementById("state_code").value="0";
	  			  document.getElementById("trade_type_code").value="1111";		
					  document.getElementById("bpm_id").value="1111";		
						document.indexForm.submit();
    }else if(val=='1'){  	
    	 			document.indexForm.action='/doTradeReg.do';//禁用
    	 			document.getElementById("state_code").value="1";
   	 			  document.getElementById("trade_type_code").value="1112";			
					  document.getElementById("bpm_id").value="1112";		
						document.indexForm.submit();
    }
  }
 }
 
 
 function ChangeOrg(){
	document.getElementById("org1").style.display = "none";
	document.getElementById("org2").style.display = "inline";
	//document.getElementById("org_id").value = "";
}

 
function submitPasswd(){
	if(document.getElementById("passwd").value == ""){
		alert("请填写用户密码！");
		document.getElementById("passwd").focus();
		return false;
	}
	
	if(document.getElementById("c_passwd").value == ""){
		alert("请填写确认密码！");
		document.getElementById("c_passwd").focus();
		return false;
	}
	
	if(document.getElementById("passwd").value != document.getElementById("c_passwd").value ){
		alert("两次输入的密码不一致！");
		document.getElementById("c_passwd").value = "";
		document.getElementById("c_passwd").focus();
		return false;
	}
	
	document.addForm.submit();
}

function   clearSBC(){ 
window.clipboardData.setData( 'text ',clipboardData.getData( 'text ').replace(/[\uFF00-\uFFFF]/g, ' ')) 
} 
